using System.Collections.Generic;

namespace AIFSContentManagementSystem.ListExtensions
{
    /// <summary>
    /// List is a wrapper for List<T> to support OnAddNewItem event.
    /// </summary>
    public class ListWithEvents<T>
    {
        public event AddNewToListWithEvents<T> OnAddNewItem;

        public ListWithEvents()
        {
            innerList = new List<T>();
        }

        List<T> innerList;        

       
        public static implicit operator List<T>(ListWithEvents<T> list)
        {
            return list.innerList;
        }

        
        public void Add(T item)
        {
            if (OnAddNewItem != null)
            {
                AddNewToListEventArgs<T> args = new AddNewToListEventArgs<T>(item);
                OnAddNewItem(this, args);
            }

            this.innerList.Add(item);
        }

        public void Add(List<T> list)
        {
            if (list == null)
                return;

            foreach (T item in list)
            {
                Add(item);
            }
        }
    }
}
